// -----------------------------------------------------------
// Game Framework
// Copyright © 2024-2024 deadcycle. All rights reserved.
// Homepage: https://deadcycle.gitee.io
// Feedback: deadcycle@163.com
// -----------------------------------------------------------

#if ODIN_INSPECTOR

using System;
using System.Collections.Generic;
using System.Reflection;

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;

using UnityEditor;

namespace ComponentAutoBind.Editor
{
    /// <summary>
    /// 使用Odin处理Inspector。
    /// </summary>
    [CustomEditor(typeof(AutoBindGlobalSetting))]
    public class AutoBindGlobalSettingInspector : OdinEditor { }

    public class AutoBindGlobalSettingAttrProcessor : OdinAttributeProcessor<AutoBindGlobalSetting>
    {
        private readonly Dictionary<string, Action<List<Attribute>>> m_FieldProcessorDict;

        public AutoBindGlobalSettingAttrProcessor()
        {
            m_FieldProcessorDict = new Dictionary<string, Action<List<Attribute>>>
            {
                { "m_Namespace", FieldNamespace },
                { "m_ScriptFolderPath", FieldScriptFolderPath },
                { "m_Authors", FieldAuthors },
                { "m_CompanyName", FieldCompanyName },
                { "m_ScriptHeader", FieldScriptHeader },
                { "m_HelperAssemblyNames", FieldHelperAssemblyNames },
            };
        }

        public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member,
            List<Attribute> attributes)
        {
            if (member.MemberType == MemberTypes.Field &&
                m_FieldProcessorDict.TryGetValue(member.Name, out Action<List<Attribute>> fieldProcessor))
            {
                fieldProcessor.Invoke(attributes);
            }
        }

        private void FieldNamespace(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("默认命名空间"));
        }

        private void FieldScriptFolderPath(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("默认代码脚本保存目录"));
            attributes.Add(new FolderPathAttribute() { RequireExistingPath = true });
        }

        private void FieldAuthors(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("开发者列表"));
        }

        private void FieldCompanyName(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("公司英文名"));
        }

        private void FieldScriptHeader(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("脚本头部信息"));
        }

        private void FieldHelperAssemblyNames(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("绑定规则辅助器查找程序集"));
        }
    }
}
#endif